lib = Dir('lib')
build = Dir('build')
src = Dir('src')
inc = Dir('include')

prefix = Dir(ARGUMENTS.get('prefix', '.'))
prefix_lib = prefix.Dir('lib')
prefix_inc = prefix.Dir('include')

lib_paths = [prefix_lib, lib]
cpp_paths = [prefix_inc, inc]

ccflags = ['-Wall', '-Werror']
if 'debug' in COMMAND_LINE_TARGETS:
	ccflags += ['-g']

BuildDir(build, src, duplicate=0)

build_sources = [build.File('diastream.cpp')]
test_sources = [build.File('test.cpp')]

env = Environment(CPPPATH=cpp_paths, CCFLAGS=ccflags, LIBPATH=lib_paths)

config = Configure(env)
config.CheckLibWithHeader('gzstream', 'gzstream.h', 'cpp')
config.CheckLib('z')
env = config.Finish()

libdiastream = env.SharedLibrary(lib.File('libdiastream.so'), build_sources)
Alias('libdiastream', libdiastream)

test = env.Program(File('test'), test_sources, LIBS=['diastream', 'gzstream', 'z'])

if prefix != Dir('.'):
	Alias('install', env.Install(prefix_lib, libdiastream))
	Alias('install', env.Install(prefix_inc, inc.Entry('diastream.hpp')))

Default(libdiastream)

Alias('debug', libdiastream)
